<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>反馈页面</title>
    <script type="text/javascript" src="../../res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript"  src="../../layui/layui.all.js" ></script>
    <script type="text/javascript" src="../../js/Tools.js" ></script>
    <link rel="stylesheet" type="text/css" href="../../layui/css/layui.css" />
    <style>
        body{
            padding: 10px 20px 10px 10px;
        }

    </style>

    <script>
        $.ajaxSetup({
            async: false
        });
    </script>
</head>
<body>
<form class="layui-form" id="atsSchemeForm">
    <input type="hidden" name="schemeId" id="schemeId" lay-verify="schemeId" autocomplete="off" class="layui-input">
    <input type="hidden" name="schemeType" id="schemeType" lay-verify="schemeType" autocomplete="off" class="layui-input">
    <input type="hidden" name="remark" id="remark" lay-verify="remark" autocomplete="off" class="layui-input">

    <label class="layui-form-label"></label>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">实施情况</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入方案实施情况" class="layui-textarea" name="resultExp" id="resultExp"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">实施效果</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入方案实施效果" class="layui-textarea" name="resultEffect" id="resultEffect"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">实施附件</label>
        <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button><span id="resultFile"></span>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="button" class="layui-btn" lay-submit="" lay-filter="demo1" id="subBtn" value="立即提交"/>
            <input type="reset" class="layui-btn layui-btn-primary" value="重置"/>
        </div>
    </div>
</form>

<script>
    //取到上一个页面传过来的id
    var schemeId = getQueryString("schemeId");
    var remark=getQueryString("remark");
    var schemeType = getQueryString("schemeType");
    $("#remark").val(remark);
    $("#schemeId").val(schemeId);
    $("#schemeType").val(schemeType);
    var str="";
    layui.use(['form', 'layedit', 'laydate','tree','element','upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , tree = layui.tree
            , element = layui.element
            , upload = layui.upload;

        //指定允许上传的文件类型
        upload.render({
            elem: '#test3'
            ,url: getRootPath() + 'atsSchemeAction/uploadFile'
            ,accept: 'file' //普通文件
            ,done: function(res){
                $("#resultFile").text(res.msg);
            }
        });


        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });





        //自定义验证规则
        form.verify({
            resultExp: function(value){
                if(!value.length){
                    return '实施情况不能包含空格';
                }
            },
            resultEffect: function(value){
                if(!value.length){
                    return '实施效果不能包含空格';
                }
            }
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            var url = getRootPath() + "atsSchemeAction/addOrUpdate";

            data.field.resultFile=$("#resultFile").text();

            $.ajax({
                url: url,
                type: "post",
                data:data.field,
                dataType: "json",
                success: function (obj) {
                        alert(obj.msg);
                        layer.msg(obj.msg, {
                            icon: 1,
                            time: 1000,
                        }, function () {
                            window.parent.location.reload();//刷新父页面
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                }, error: function (e) {
                    alert('失败了');
                }

            });
        });
    });

</script>

</body>
</html>